package org.wyn.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.wyn.common.ResultType;
import org.wyn.mongodb.bean.User;
import org.wyn.mongodb.bean.Message.Mee;
import org.wyn.service.IProfileTabService;

import com.google.inject.Inject;

/**
 * 留言action(首页的)
 * @author wyn
 *
 */
@Namespace("/message")
@ParentPackage("security")
public class MessageAction extends WynActionSupport{
	/**
	 * 去"首页-留言"页面
	 * @return
	 */
	@Action(value="goMessage",results = {@Result(name = SUCCESS, type = ResultType.FREEMARKER, location = "message.ftl")})
	public String goMessage(){
		List<Mee> mees = iProfileTabService.viewMessageByToUser(getLoginUser().getUserName());
		getRequest().setAttribute("mees", mees);
		return SUCCESS;
	}
	@Action(value="leave_mesage",results = {@Result(type = ResultType.PLAIN_TEXT)})
	public void leaveMessage(){
		User user = getLoginUser();
		iProfileTabService.leaveMessage(user.getUserName(), user.getUserName(), messageBody);
	}
	@Inject
	private IProfileTabService iProfileTabService;
	private String messageBody;
	private static final long serialVersionUID = 1L;
	public IProfileTabService getiProfileTabService() {
		return iProfileTabService;
	}
	public void setiProfileTabService(IProfileTabService iProfileTabService) {
		this.iProfileTabService = iProfileTabService;
	}
	public String getMessageBody() {
		return messageBody;
	}
	public void setMessageBody(String messageBody) {
		this.messageBody = messageBody;
	}

}
